Repository navigation
FEAT: Add native Claude target and bounded tool execution - #4021
Richard Lundeen (richlundeen) merged 9 commits into
Conversation
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟡 Changes recommended
The Claude target can expose subscription-key credentials through persisted conversation metadata, and tools=None now causes previously accepted requests to fail.
2 open issues
What changed in this PR
Adds a native Claude target to PyRIT’s target framework and shared, bounded tool execution through LiteLLM.
Changes:
- Introduces Claude-specific routing, credential handling, capabilities, and JSON-object formatting.
- Adds validated tool execution with round limits, scoped providers, linked results, and replayable history.
- Updates dependencies and Docker installs, with documentation, unit coverage, and opt-in Anthropic integration tests.
| File | Description |
|---|---|
uv.lock |
Aligns LiteLLM minimum-version requirements. |
tests/unit/prompt_target/target/test_litellm_chat_target.py |
Tests tool execution, limits, failures, cleanup, and replay. |
tests/unit/prompt_target/target/test_claude_chat_target.py |
Tests Claude routing, credentials, capabilities, and adapter behavior. |
tests/unit/infra/test_docker_ci.py |
Tests Docker installation and source-specific smoke checks. |
tests/integration/targets/test_claude_chat_target_integration.py |
Adds opt-in live Claude tool and JSON tests. |
pyrit/prompt_target/litellm_chat_target.py |
Implements shared bounded tool execution. |
pyrit/prompt_target/common/target_capabilities.py |
Adds known Claude capability profiles. |
pyrit/prompt_target/common/discover_target_capabilities.py |
Handles LiteLLM JSON enforcement and suppresses tools during probes. |
pyrit/prompt_target/claude_chat_target.py |
Implements native Claude routing and JSON formatting. |
pyrit/prompt_target/__init__.py |
Lazily exports ClaudeChatTarget. |
pyproject.toml |
Raises the LiteLLM minimum version. |
docker/Dockerfile |
Installs LiteLLM and adds import smoke checks. |
doc/myst.yml |
Adds the Claude guide to navigation. |
doc/code/targets/claude_chat_target.md |
Documents setup, tools, JSON output, and integration testing. |
doc/code/targets/0_prompt_targets.md |
Lists the Claude target and links its guide. |
Review effort: Balanced
|
Suggestion: let a tool end the turn when its own infrastructure fails
Proposed change (small):
Context: this comes from sandboxed code execution, where a model's |
Resolve the LiteLLM test import conflict by preserving executable-tool imports and the public lazy target export. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Preserve null passthrough compatibility, stop on explicit infrastructure outages with complete tool evidence, and isolate the Docker release-probe test from optional dependencies. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
Addressed both concerns from this review in 4a66169: subscription-key credentials are excluded case-insensitively from persisted Claude identifiers, and explicit |
|
Implemented the infrastructure-failure behavior from this suggestion in 4a66169. Tools can raise the public |
Richard Lundeen (richlundeen)
left a comment
There was a problem hiding this comment.
Automated review completed. No blocking concerns remain. This review records source coverage; it does not authorize merge.
Integrate exact main 6053ef3. Retain the shared ToolInfrastructureError with the additive invoked contract while preserving Claude target fixes. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Behnam (behnam-o)
left a comment
There was a problem hiding this comment.
Thanks for the change, here are some comments from me and Claude.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Extract run_tool_loop_async and dispatch_tool_call_async into pyrit/prompt_target/common/tool_loop.py and route both OpenAIResponseTarget and LiteLLMChatTarget through it, so the same Tool behaves the same on both: pydantic-only argument validation, ToolLoopStop on every early stop, and propagation of tool and continuation failures. Keep ClaudeChatTarget thin: lift environment variable names and credential header redaction into LiteLLMChatTarget class attributes, pass api_key through unchanged, and return JSON formatter output for the caller to validate. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Richard Lundeen (richlundeen)
left a comment
There was a problem hiding this comment.
Automated review completed. No blocking concerns remain. This review records source coverage; merging is handled separately.


Description
Add a public
ClaudeChatTargetthat uses LiteLLM's native Anthropic transport and can run executable tools. Share bounded tool execution withLiteLLMChatTargetwithout changing transport behavior for callers that do not use executable tools.pyrit/prompt_target/common/tool_loop.py) used by bothOpenAIResponseTargetandLiteLLMChatTarget, so the sameToolbehaves the same on both: bounded rounds, direct tools and scoped providers, pydantic argument validation, linked results,ToolLoopStopmetadata on every early stop, cancellation cleanup, and replayable history stored by the normalizer.Previously, we accessed Claude through
OpenAIChatTargetand Anthropic's OpenAI-compatible endpoint. That compatibility layer squashes all system/developer messages into one top-level system prompt, hoisting them ahead of the conversation rather than preserving their original positions. It also ignores strict tool-schema enforcement and does not support OpenAI's unconstrainedjson_objectresponse format. These are compatibility-layer limitations, not a lack of Claude support in PyRIT.ClaudeChatTargetinstead uses the native Anthropic Messages API through LiteLLM, with Claude-specific configuration and JSON-object formatting. The shared bounded tool loop adds local execution and stores linked tool calls/results for later turns; existing callers without executable tools retain their transport behavior. This does not promise arbitrary mid-conversation system messages or strict native JSON-schema output for every Claude model. See Anthropic's compatibility limitations.